home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5220 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to convert char to hex in C++?
  5. Date: Sat, 03 Feb 1996 02:19:00 GMT
  6. Organization: Netcom
  7. Message-ID: <3112c479.88246912@nntp.ix.netcom.com>
  8. References: <DM679K.BD1@undergrad.math.uwaterloo.ca>
  9. NNTP-Posting-Host: ix-dc14-21.ix.netcom.com
  10. X-NETCOM-Date: Fri Feb 02  6:19:01 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. hylo@neumann.uwaterloo.ca (Grace Hai Yan Lo) wrote:
  14.  
  15. >     I just wonder if anyone know how to convert a char (e.g. 'a') to
  16. > hex digit (i.e. 61 for 'a') in C++?  Somehow the cout << hex << n <<endl;
  17. > works for n being an integer but not a character.  Thanks.
  18.  
  19. Make it an int:
  20.  
  21.     cout << hex << int('a') << endl;
  22.  
  23. In C++ char is an integer in that you can do arithmentic on it and it
  24. can be converted to other integer types.  The conversion to another
  25. integral type converts the internal representation.
  26.  
  27. Note that 'a' does not necessarly convert to 61 hex.  It does in
  28. ASCII, but there are other character sets.
  29.  
  30.  
  31. Michael M Rubenstein
  32.